package com.rs.lc.pm.model.utils;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.joda.time.DateTime;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class Page {
    public final static int PAGE_SHOW_COUNT = 20;
    private int page = 1;
    private int count = 0;
    private int totalCount = 0;
    private long totalCost = 0;
    private long orgId;
    private Map<String, String> filter = Maps.newHashMap();
    private String orderField;
    private String orderDirection;
    private String keywords;
    private String status;
    private String type;
    private Date startDate;
    private Date endDate;
    private List<Long> statusList = Lists.newArrayList();
    private Map sorting = Maps.newHashMap();

    public long getTotalCost() {
        return totalCost;
    }

    public void setTotalCost(long totalCost) {
        this.totalCost = totalCost;
    }

    public String getType() {
        return "".equals(type) ? null : type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getStatus() {
        return "".equals(status) ? null : status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return null == endDate ? null : new DateTime(endDate).plusDays(1).toDate();
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int pageNum) {
        this.page = pageNum;
    }

    public int getCount() {
        return count > 0 ? count : PAGE_SHOW_COUNT;
    }

    public void setCount(int pageSize) {
        this.count = pageSize;
    }

    public String getOrderField() {
        return orderField;
    }

    public void setOrderField(String orderField) {
        this.orderField = orderField;
    }

    public String getOrderDirection() {
        return "desc".equals(orderDirection) ? "desc" : "asc";
    }

    public void setOrderDirection(String orderDirection) {
        this.orderDirection = orderDirection;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public String getKeywords() {
        return "".equals(keywords) ? null : keywords;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    public int getStartIndex() {
        int pageNum = this.getPage() > 0 ? this.getPage() - 1 : 0;
        return pageNum * this.getCount();
    }

    public Map<String, String> getFilter() {
        return filter;
    }

    public void setFilter(Map<String, String> filter) {
        this.filter = filter;
    }

    public List<Long> getStatusList() {
        return statusList;
    }

    public void setStatusList(List<Long> statusList) {
        this.statusList = statusList;
    }

    public long getOrgId() {
        return orgId;
    }

    public void setOrgId(long orgId) {
        this.orgId = orgId;
    }

    public static int getPageShowCount() {
        return PAGE_SHOW_COUNT;
    }

    public Map getSorting() {
        return sorting;
    }

    public void setSorting(Map sorting) {
        this.sorting = sorting;
    }
}

